<template>
  <div class="platform-stats">
    <h2 class="stats-title">平台数据</h2>
    <div class="stats-container">
      <div class="stat-item">
        <el-icon class="stat-icon"><Calendar /></el-icon>
        <div class="stat-info">
          <div class="stat-value">{{ stats.activityCount || 0 }}<sup>+</sup></div>
          <div class="stat-label">活动总数</div>
        </div>
      </div>
      
      <div class="stat-item">
        <el-icon class="stat-icon"><User /></el-icon>
        <div class="stat-info">
          <div class="stat-value">{{ stats.volunteerCount || 0 }}<sup>+</sup></div>
          <div class="stat-label">志愿者总数</div>
        </div>
      </div>
      
      <div class="stat-item">
        <el-icon class="stat-icon"><Timer /></el-icon>
        <div class="stat-info">
          <div class="stat-value">{{ stats.totalServiceHours || 0 }}<sup>+</sup></div>
          <div class="stat-label">累计服务时长</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Calendar, User, Timer } from '@element-plus/icons-vue'
import { getPlatformStats } from '@/api/stat'

const stats = ref({})

const fetchStats = async () => {
  try {
    const { data } = await getPlatformStats()
    stats.value = data
  } catch (error) {
    console.error('获取平台统计数据失败:', error)
  }
}

onMounted(() => {
  fetchStats()
})
</script>

<style scoped>
.platform-stats {
  padding: 20px;
}

.stats-title {
  font-size: 24px;
  color: #303133;
  margin-bottom: 20px;
  text-align: center;
}

.stats-container {
  display: flex;
  justify-content: space-around;
  gap: 30px;
  flex-wrap: wrap;
}

.stat-item {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.stat-icon {
  font-size: 32px;
  color: #409EFF;
  background: #ecf5ff;
  padding: 15px;
  border-radius: 8px;
}

.stat-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
}

.stat-value sup {
  font-size: 14px;
  color: #409EFF;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

@media (max-width: 768px) {
  .stat-item {
    min-width: 100%;
  }
}
</style> 